package com.example.testdiyexceltableheader.demos.service;

import com.example.testdiyexceltableheader.demos.model.Target;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class DataService {


    //表头
    public List<Target> getHeader() {

        List<Target> targets = new ArrayList<>();
        for (int i = 0; i < 10; i++) {

            Target target = new Target();
            targets.add(target);
            target.setName("表头" + i);
            if (i % 2 == 0) {
                target.setType("dict");
                target.setDictKey(String.valueOf(i));
                continue;
            }
            target.setType("txt");
        }

        return targets;
    }

    public Map<String, List<String>> getRole() {

        Map<String, List<String>> stringListHashMap = new HashMap<>();

        //0 2 4 6 8 10

        for (int i = 0; i < 10; i++) {
            stringListHashMap.put(String.valueOf(i), getList());
        }

        return stringListHashMap;
    }

    private List<String> getList() {
        Random random = new Random();
        List<String> strings = new ArrayList<>();
        // 生成一个0到9之间的随机整数
        int randomNumber = random.nextInt(10);

        if (randomNumber == 0) {
            randomNumber = 1;
        }
        for (int i = 0; i < randomNumber; i++) {
            strings.add(UUID.randomUUID().toString());
        }


        return strings;
    }

}
